package AOP;

import Messages.AMessage;
import Messages.AMessage.GlobalNames;

import com.sun.org.omg.CORBA.ParameterModeHelper;

import jade.core.Profile;
import jade.core.ProfileException;
import jade.core.ProfileImpl;
import jade.core.Runtime;

import jade.tools.rma.rma;
import jade.util.leap.Properties;
import jade.wrapper.AgentController;
import jade.wrapper.ContainerController;
import jade.wrapper.StaleProxyException;

public class StartAgentPlatform {

	/**
	 * @param args
	 * @throws ProfileException 
	 */
	
	@SuppressWarnings("unused")
	public static void main(String[] args) throws ProfileException {
		String host = "localhost";
		String port = "";
		String name = "AOP";
		
		ContainerController cController;
		Runtime rt = Runtime.instance();//retrieve the singleton instance of the JADE Runtime
		Profile p;
		//Create a container
		p = new ProfileImpl();
		cController = rt.createMainContainer(p);			
		rt.setCloseVM(true);
		
		
		
		if(cController != null){
			try{
				//start GUI interface Agent
				AgentController ac = cController.createNewAgent("gui", rma.class.getName(), null);
				ac.start();
				
				//---add Agents in this zone---
				Printer.init();
				//add Agent - register agent into DF, receive acl msg, printout and reply
				CreateAgent(cController,GlobalNames.getAreaCode(AMessage.worlds[0])+GlobalNames.FLOOR_HEATER_AGENT.get(),"Agents.FloorHeater");
				CreateAgent(cController,GlobalNames.getAreaCode(AMessage.worlds[0])+GlobalNames.TEMPERATURE_SENSOR_AGENT.get(),"Agents.Sensor.TemperatureSensor");
				CreateAgent(cController, GlobalNames.getAreaCode(AMessage.worlds[0])+GlobalNames.OFFICE_REGION_AGENT.get(), "Agents.OfficeRegion");
				
				CreateAgent(cController,AMessage.worlds[0],"Agents.Sensor.World");
				////////////////
				
				CreateAgent(cController,GlobalNames.getAreaCode(AMessage.worlds[1])+GlobalNames.FLOOR_HEATER_AGENT.get(),"Agents.FloorHeater");
				CreateAgent(cController,GlobalNames.getAreaCode(AMessage.worlds[1])+GlobalNames.TEMPERATURE_SENSOR_AGENT.get(),"Agents.Sensor.TemperatureSensor");
				CreateAgent(cController, GlobalNames.getAreaCode(AMessage.worlds[1])+GlobalNames.OFFICE_REGION_AGENT.get(), "Agents.OfficeRegion");
				
				CreateAgent(cController,AMessage.worlds[1],"Agents.Sensor.World");
				////////////////
				
				CreateAgent(cController,GlobalNames.getAreaCode(AMessage.worlds[2])+GlobalNames.FLOOR_HEATER_AGENT.get(),"Agents.FloorHeater");
				CreateAgent(cController,GlobalNames.getAreaCode(AMessage.worlds[2])+GlobalNames.TEMPERATURE_SENSOR_AGENT.get(),"Agents.Sensor.TemperatureSensor");
				CreateAgent(cController, GlobalNames.getAreaCode(AMessage.worlds[2])+GlobalNames.OFFICE_REGION_AGENT.get(), "Agents.OfficeRegion");
				
				CreateAgent(cController,AMessage.worlds[2],"Agents.Sensor.World");
				////////////////
				
				CreateAgent(cController,GlobalNames.getAreaCode(AMessage.worlds[3])+GlobalNames.FLOOR_HEATER_AGENT.get(),"Agents.FloorHeater");
				CreateAgent(cController,GlobalNames.getAreaCode(AMessage.worlds[3])+GlobalNames.TEMPERATURE_SENSOR_AGENT.get(),"Agents.Sensor.TemperatureSensor");
				CreateAgent(cController, GlobalNames.getAreaCode(AMessage.worlds[3])+GlobalNames.OFFICE_REGION_AGENT.get(), "Agents.OfficeRegion");
				
				CreateAgent(cController,AMessage.worlds[3],"Agents.Sensor.World");
				////////////////
				
				

				CreateAgent(cController, "01"+GlobalNames.USER_AGENT.get(), "Agents.User");
				CreateAgent(cController, "01"+GlobalNames.BIN_AGENT.get(), "Agents.Bin");
				CreateAgent(cController, "02"+GlobalNames.BIN_AGENT.get(), "Agents.Bin");
				
				CreateAgent(cController,"01"+AMessage.GlobalNames.VACUUM_CLEANER_AGENT.get(),"Agents.VacuumCleaner");
				CreateAgent(cController,"02"+AMessage.GlobalNames.VACUUM_CLEANER_AGENT.get(),"Agents.VacuumCleaner");
				CreateAgent(cController,"03"+AMessage.GlobalNames.VACUUM_CLEANER_AGENT.get(),"Agents.VacuumCleaner");
			}
			catch (Exception e){
				e.printStackTrace();
			}
		}	
	}
	
	private static void CreateAgent(ContainerController cController, String agent_name, String agent_class) throws StaleProxyException{
		//add Agent AgentSender
		AgentController ac = cController.createNewAgent(agent_name, agent_class, null);
		ac.start();
	}
}
